package com.hua.yuan.live.view.holder_view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hua.yuan.common.BaseHolderView;
import com.hua.yuan.live.R;
import com.hua.yuan.live.listener.OnBuyClickListener;
import com.hua.yuan.live.repertory.cloud_data.res.LiveVideoBean;

import java.util.List;

/**
 * 直播列表的ITEM
 */
public class HolderView_History implements BaseHolderView<LiveVideoBean>,View.OnClickListener{


    private ImageView mIvAnchorHeaderUrl;
    private TextView mTvTitle;
    private ImageView mIvAnchorImage;
    private TextView mTvTime;

    private int mPosition;

    private OnBuyClickListener mOnBuyClickListener;

    public HolderView_History(View pView, int pPosition) {

        mIvAnchorHeaderUrl = pView.findViewById(R.id.iv_anchorheader_live_history);
        mTvTitle = pView.findViewById(R.id.tv_title_live_history);
        mIvAnchorImage = pView.findViewById(R.id.iv_anchor_img_live_history);
        mTvTime=pView.findViewById(R.id.tv_time_live_history);
        this.mPosition=pPosition;
        mIvAnchorImage.setOnClickListener(this);
    }

    public void setOnBuyClickListener(OnBuyClickListener pOnLiveClickListener){

        this.mOnBuyClickListener=pOnLiveClickListener;
    }


    @SuppressLint({"StringFormatInvalid", "StringFormatMatches"})
    @Override
    public void bindHolder(@NonNull List<LiveVideoBean> pList, int position, @NonNull Context pContext) {

        if (pList == null || pList.size() == 0 || (position > pList.size())) {
            return;
        }

        LiveVideoBean liveVideoBean = pList.get(position);
        if (liveVideoBean == null) {
            return;
        }
        //直播时间
        String liveTime = liveVideoBean.getStatrTime();


        if (!TextUtils.isEmpty(liveTime) && (!TextUtils.isEmpty(liveTime))) {

            mTvTime.setText(liveTime);
        }

        String title = liveVideoBean.getTitle();

        if (!TextUtils.isEmpty(title) && (!TextUtils.isEmpty(title))) {

            mTvTitle.setText(String.valueOf(title));
        }
        //TODO 头像的url和主播头像url

    }

    @Override
    public void onClick(View v) {

        if(R.id.iv_anchor_img_live_history ==v.getId()){

            mOnBuyClickListener.click(mPosition);

        }
    }
}
